package com.eleadmin.common.system.controller;

import java.util.List;

import javax.annotation.Resource;

import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.eleadmin.common.core.annotation.OperationLog;
import com.eleadmin.common.core.web.ApiResult;
import com.eleadmin.common.core.web.BaseController;
import com.eleadmin.common.core.web.PageResult;
import com.eleadmin.common.system.entity.Message;
import com.eleadmin.common.system.param.MessageParam;
import com.eleadmin.common.system.service.MessageService;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;


@Api(tags = "留言表管理")
@RestController
@RequestMapping("/system/message")
public class MessageController extends BaseController {
    @Resource
    private MessageService messageService;

    @OperationLog
    @ApiOperation("分页查询留言板")
    @GetMapping("/page")
    public ApiResult<PageResult<Message>> page(MessageParam param) {
        PageResult<Message> commentPageResult = messageService.pageRel(param);
        return success(commentPageResult);

    }

    @OperationLog
    @ApiOperation("查询全部留言表")
    @GetMapping()
    public ApiResult<List<Message>> list(MessageParam param) {
        List<Message> comments = messageService.listRel(param);
        return success(comments);

    }

    @OperationLog
    @ApiOperation("添加留言表")
    @PostMapping()
    public ApiResult<?> save(@RequestBody Message comment) {
         
        if (messageService.save(comment)) {
            return success("留言成功");
        }
        return fail("留言失败");
    }

    @OperationLog
    @ApiOperation("删除留板")
    @DeleteMapping("/{id}")
    public ApiResult<?> remove(@PathVariable("id") Integer id) {
        if (messageService.removeById(id)) {
            return success("删除成功");
        }
        return fail("删除失败");
    }
    @OperationLog
    @ApiOperation("批量删除留言表")
    @DeleteMapping("/batch")
    public ApiResult<?> removeBatch(@RequestBody List<Integer> ids) {
        if (messageService.removeByIds(ids)) {
            return success("删除成功");
        }
        return fail("删除失败");
    }

}
